package com.smart.seata.order.service.impl;

import com.smart.seata.order.entity.Order;
import com.smart.seata.order.mapper.OrderMapper;
import com.smart.seata.order.service.OrderService;
import com.smart.seata.order.service.feign.StockService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Resource
    OrderMapper orderMapper;
    @Resource
    StockService stockService;

    @GlobalTransactional
    @Override
    public String createOrder() {
        Order order = new Order();
        order.setOrderNo(1L);
        int insert = orderMapper.insert(order);
        log.info("" + insert);
        boolean decr = stockService.update(1L, 10L);
        log.info(decr + "");
        return "success";
    }
}
